.section .data
msgA: .asciz" Please enter a value for A: \n"
msgB: .asciz" Please enter a value for B: \n"
msgC: .asciz" Please enter a value for C: \n"


Al: .asciz"A"
Bl: .asciz"B"
Cl: .asciz"C"
cad4: .asciz "%d"
msg: .asciz "The highest value is: %c\n"

.section .bss
A: .space 4
B: .space 4
C: .space 4

.section .text
.globl _start
_start:
 	pushl $msgA  #send msgA as a parameter 
 	call outmsg  #call the procedure which function is ask for the A value
        addl $4, %esp  #clear the stack 
        leal A, %eax  #obtain the  A address
        pushl %eax  #send the A address to the readmsg procedure
        call readmsg #call the readmsg  which function is read the input
        addl $4, %esp #clear the stack 
        pushl $msgB
 	call outmsg
        addl $4, %esp
 	leal B, %eax
        pushl %eax 	
        call readmsg
        addl $4, %esp
	pushl $msgC
 	call outmsg
 	leal C, %eax
 	pushl %eax
 	call readmsg
        call comparison #call the procedure to compare the 3 inputs.  It will print the highest one
        movl $1, %eax
 	movl $0, %ebx
 	int $0x80
outmsg: pushl %ebp        #prologue
        movl %esp, %ebp   #prologue
        movl 8(%ebp), %eax #obtain the parameter
        pushl %eax     #push the parameter to print later
        call printf     #print the parameter
        addl $4, %esp   #clear the satck
        leave
        ret

readmsg: pushl %ebp
         movl %esp, %ebp
         movl 8(%ebp), %eax
         pushl %eax
         leal cad4, %eax #carga la direccion de la cadena de formato
         pushl %eax #pone esa direccion en la pila
         call scanf
         addl $8, %esp
         leave 
         ret

       
comparison:pushl %ebp
           movl %esp, %ebp
          movl A, %eax 	
       	movl B, %ebx 	
	movl C, %ecx 	
	cmpl %ebx, %eax 	# compara a con b
	jg amayorb 	# si a>b salta a amayorb
	cmpl %ecx, %ebx 	# compara b con c
	jl bmenorc
        pushl Bl 	# si b<c salta a mnenorc
	jmp fin 	# salta a fin
bmenorc: pushl Cl	# cuando c es el mayor
	jmp fin 	# salta a fin
amayorb: cmpl C, %eax 	# compara a con c
	jl amenorc 	# si a<c salta a amenorc
	pushl Al 	# cuando a es el mayor
	jmp fin 	# salta a fin
amenorc: pushl Cl 	# cuando c es el mayor
fin:   leal msg, %eax
       pushl %eax
     call printf
     leave
           ret      
